#include <stdio.h>
#include <stdlib.h>

// 链表的实现，可以添加和删除
struct Node
{
    int value;
    struct Node *next;
};
void insertNode(struct Node **head, int value){
    struct Node *pre;
    struct Node *current;
    struct Node *new;
    current = *head;
    pre = NULL;
    while(current!=NULL&&current->value<value){
        pre=current;
        current = current->next;
    }
    new=(struct Node *)malloc(sizeof(struct Node));
    new->value=value;
    new->next=current;
    if(pre==NULL){
        *head=new;
    }else{
        pre->next=new;
    }
}
void printNode(struct Node *head){
    struct Node *current;
    current=head;
    while(current!=NULL){
        printf("%d ",current->value);
        current=current->next;
    }
    putchar('\n');
}
void deleteNode(struct Node **head, int value){
    struct Node *pre;
    struct Node *current;
    current=*head;
    pre=NULL;
    while(current!=NULL&&current->value!=value){
        pre=current;
        current=current->next;
    }
    if(current==NULL){
        printf("Not found\n");
        return;
    }
    if(pre==NULL){
        *head=current->next;
    }else{
        pre->next=current->next;
    }
    free(current);
}
void main(){
    struct Node *head = NULL;
    int input;
    printf("请输入数字，-1退出\n");
    while(1)
    {
        scanf("%d",&input);
        if(input == -1){
            break;
        }
        insertNode(&head,input);
        printNode(head);
    }
    printf("请输入删除的数字，-1退出\n");
    while(1)
    {
        scanf("%d",&input);
        if(input == -1){
            break;
        }
        deleteNode(&head,input);
        printNode(head);
    }
}